from django.db import models
from DjangoUeditor.models import UEditorField
from django.contrib.auth import get_user_model
from apps.users.models import Users


# Create your models here.
class Products(models.Model):
    """产品分类"""
    choice_product = (('0', '通用'), ('1', 'H710S2'), ('2', 'H710Pro'), ('3', 'H8900'), ('4', 'H9100'))
    name = models.CharField(verbose_name='产品名称', max_length=2, choices=choice_product, unique=True, help_text='产品分类')

    def __str__(self):
        return self.get_name_display()


class Versions(models.Model):
    """定义产品的版本"""
    name = models.CharField(verbose_name='程序基线版本号', max_length=100, unique=True, help_text='基线版本号')

    def __str__(self):
        return self.name


class Tags(models.Model):
    """标签名称"""
    name = models.CharField(verbose_name='标签名', max_length=20, help_text='自定义标签名')

    def __str__(self):
        return self.name


class Document(models.Model):
    """文档"""
    title = models.CharField(verbose_name='标题', max_length=50, unique=True, help_text='文档标题')
    product = models.ForeignKey(verbose_name='产品分类', to=Products, on_delete=models.CASCADE, help_text='文档对应产品')
    content = UEditorField(verbose_name='正文', width='80%', height=400, help_text='文档正文')
    tags = models.ManyToManyField(verbose_name='标签', to='Tags', help_text='自定义文档标签')
    create_user = models.ForeignKey(verbose_name='创建人', to=Users, on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='最后更新时间', auto_now=True)

    def __str__(self):
        return self.title


class FAQ(models.Model):
    """FAQ"""
    title = models.CharField(verbose_name='标题', max_length=50, help_text='FAQ标题')
    product = models.ForeignKey(verbose_name='产品分类', to=Products, on_delete=models.CASCADE, help_text='FAQ对应产品')
    content = UEditorField(verbose_name='正文', width='80%', height=400, help_text='FAQ正文')
    tags = models.ManyToManyField(verbose_name='文章标签', to=Tags)
    create_user = models.ForeignKey(verbose_name='创建人', to=Users, on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='最后更新时间', auto_now=True)

    def __str__(self):
        return self.title


class Tools(models.Model):
    """工具下载"""
    title = models.CharField(verbose_name='标题', max_length=50, help_text='工具标题')
    content = UEditorField(verbose_name='正文+附件', width='80%', height=400, help_text='工具说明使用说明+下载地址')
    tags = models.ManyToManyField(verbose_name='标签', to='Tags', help_text='自定义标签')
    create_user = models.ForeignKey(verbose_name='创建人', to=Users, on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='最后更新时间', auto_now=True)

    def __str__(self):
        return self.title
